package com.zhu.controller;

import com.zhu.pojo.Debt;
import com.zhu.pojo.Income;
import com.zhu.pojo.Transform;
import com.zhu.service.DebtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DebtController {
    @Autowired
    DebtService debtService;

    @CrossOrigin //解决跨域问题
    @GetMapping("/api/debt/{username}")
    public List<Debt> list(@PathVariable("username") String username){
        return debtService.getAll(username);
    }


    @CrossOrigin //解决跨域问题
    @GetMapping("/api/debtAdmin")
    public List<Debt> listAdmin(){
        return debtService.getAllByAdmin();
    }


    @CrossOrigin //解决跨域问题
    @PostMapping("/api/queryDe")
    public List<Debt> queryList(@RequestBody Debt de) {
//        System.out.println(de);
        return debtService.getByCondition(de);
    }

    @CrossOrigin //解决跨域问题
    @PostMapping("/api/queryAdminDe")
    public List<Debt> queryListByAdmin(@RequestBody Debt de) {
//        System.out.println(de);
        return debtService.getByAdmin(de);
    }



    @CrossOrigin //解决跨域问题
    @PostMapping("/api/saveDebt")
    public String save(@RequestBody Debt de) {
        boolean flag = debtService.save(de);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @PostMapping("/api/updDebt")
    public String upd(@RequestBody Debt de) {
        boolean flag = debtService.upd(de);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @GetMapping("/api/delDebt/{id}")
    public String upd(@PathVariable("id") int id) {
        boolean flag = debtService.del(id);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }




}

